﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace Common.Logging.Loupe.Example
{
    public class LogExampleViewModel: INotifyPropertyChanged
    {
        private LogLevel _currentLevel = LogLevel.Trace;
        private LogExample _model;
        private RelayCommand<string> _writeToLogCommand;
        private RelayCommand<object> _showLogCommand;

        public LogExampleViewModel(LogExample model)
        {
            _model = model;
            _writeToLogCommand = new RelayCommand<string>((s) => _model.WriteLogMessage(CurrentLevel, s));
            _showLogCommand = new RelayCommand<object>((o) => Gibraltar.Agent.Log.ShowLiveViewer());
        }

        public event PropertyChangedEventHandler PropertyChanged = (s, e) => { };

        /// <summary>
        /// Gets or sets the currently active LogLevel
        /// </summary>
        public LogLevel CurrentLevel
        {
            get { return _currentLevel; }
            set 
            {
                if (_currentLevel != value)
                {
                    _currentLevel = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("CurrentLevel"));
                }
            }
        }
       
        /// <summary>
        /// Gets the command that is used to write to the log
        /// </summary>
        public RelayCommand<string> WriteToLogCommand
        {
            get { return _writeToLogCommand; }
        }

        public RelayCommand<object> ShowLogCommand
        {
            get { return _showLogCommand; }
        }
    }
}
